from django.shortcuts import render
from django.http import HttpResponse
import json
from .models import MfCart


# Create your views here.
def handleAdd(request):
    pass
    # # cart/add?pid=1&count=10
    # myId = request.GET['pid']
    # myCount = request.GET['count']
    #
    # item = MfCart()
    # item.pid = myId
    # item.count = myCount
    # item.save()
    #
    # result = {"code": 1, "msg": "add success"}
    # return HttpResponse(json.dumps(result))


def handleDel(request):
    pass
    # # cart/del?pid=1 删除
    # myId = request.GET['pid']
    # myData = MfCart.objects.filter(pid=myId)
    # myData.delete()
    # result = {"code": 1, "msg": "del success"}
    # return HttpResponse(json.dumps(result))


def handleUpdate(request):
    pass
    # cart/update?pid=1&count=4
    # 接收参数
    # myId = request.GET['pid']
    # myCount = request.GET['count']
    # # 查找
    # item = MfCart.objects.get(pid=myId)
    # # 修改
    # item.count = myCount
    # # 保存
    # item.save()
    # result = {"code": 1, "msg": "update success"}
    # return HttpResponse(json.dumps(result))


def handleCheck(request):
    pass
    myData = MfCart.objects.all().values()
    myList = list(myData)
    result = {"code": 1, "msg": myList}
    return HttpResponse(json.dumps(result))


#
#
def cartlist(request):
    return render(request, 'cart.html')
